<template>
  <div class="app-wrapper">
    <admin-menu />
    <div class="main-container">
      <div :class="{'fixed-header':fixedHeader}">
        <navbar />
      </div>
      <app-main />
    </div>
  </div>
</template>

<script>
import { Navbar, AppMain } from './components'
import ResizeMixin from './mixin/ResizeHandler'
import AdminMenu from '@/components/AdminMenu'

export default {
  name: 'Layout',
  components: {
    Navbar,
    AppMain,
    AdminMenu
  },
  mixins: [ResizeMixin],
  computed: {
    fixedHeader() {
      return this.$store.state.settings.fixedHeader
    }
  },
  mounted() {
    const projectId = this.$route.params.projectId
    this.initCurrentInfo(projectId)
  },
  methods: {
    initCurrentInfo(projectId) {
      let fromData = this.getFrom()
      if (!fromData) {
        this.get('/project/space', { projectId: projectId }, resp => {
          fromData = resp.data
          this.setTitle(fromData.projectName)
          this.setCurrentInfo({
            id: fromData.spaceId,
            name: fromData.spaceName
          }, {
            id: fromData.projectId,
            name: fromData.projectName
          })
        })
      } else {
        this.setTitle(fromData.projectName)
        this.setCurrentInfo({
          id: fromData.spaceId,
          name: fromData.spaceName
        }, {
          id: fromData.projectId,
          name: fromData.projectName
        })
      }
    }
  }
}
</script>
